using System;       
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Magiq.Providers.Objects;

namespace Magiq.Tests.Objects {
    public class MagiqToObjectTestConfiguration : IMagiqTestConfigurator {
        private readonly Dictionary<Type, IEnumerable> itemsByType = new Dictionary<Type, IEnumerable>();

        #region IMagiqTestConfigurator Members

        public void Persist<T>(IList<T> items) where T : class {
            itemsByType.Add(typeof (T), items);
        }

        public void SetUp()
        {
            itemsByType.Clear();
            MagiqConfigurator.Clear()
                .Register<MagiqToObjects>();
        }

        public void TearDown() {}

        public IQueryable<T> GetQueryable<T>() where T : class {
            if (!itemsByType.ContainsKey(typeof (T)))
                itemsByType.Add(typeof (T), new List<T>());

            return (IQueryable<T>) itemsByType[typeof (T)].AsQueryable();
        }

        public void Reload() {}

        #endregion
    }
}